انتقل إلى المحتوى الرئيسي

🧾 Project Sardine System Architecture Overview

This document provides a high-level overview of the architecture of Project Sardine, its interaction with external services (like Project Jupiter), core components such as printing, bill processing, MediatR usage, Server-Sent Events (SSE) for monitoring, and financial account creation.


📦 Project Structure and Responsibilities

Project Sardine is a modular backend system responsible for:

  • Checkout, bill generation, and printing
  • Real-time monitor updates using SSE
  • Financial journal integration for bills
  • User account creation and financial linkage

It interacts with services like:

  • Project Jupiter (External Print Service)
  • Project Legolas (Financial accounts, journals, transactions)

🖨️ Print Flow via Project Jupiter

The PrintCustomerReceiptEndpoint in Checkout.BillPrint.Create is responsible for printing customer receipts:

  1. Request is made to /checkout/bill/print/customer-receipt.

  2. The endpoint retrieves receipt data from ReceiptGeneratorHelper.

  3. A ReceiptDocument is created, potentially including a logo.

  4. It fetches the configured printer using IPrinterService.

  5. Sends the document to Project Jupiter, which is responsible for actual printing of:

    • 🧾 Customer receipts
    • 👨‍🍳 Kitchen receipts

Project Jupiter is an external microservice that handles printing. It receives print jobs through REST requests from Project Sardine.


🧠 MediatR for Event Broadcasting

Project Sardine uses MediatR to publish domain events and handle them asynchronously. For example:

public class BillFinanceProcessor : INotificationHandler<BroadcastEventNotification<BillResponse>>

The BillFinanceProcessor reacts to BroadcastEventNotification<BillResponse> when:

  • A bill is finished (OrderFinished)
  • It handles Safari (delivery) and non-safari bills
  • Starts a financial transaction process via Project Legolas

📡 Real-Time Monitor Updates with SSE

SSE (Server-Sent Events) is used for real-time updates to the monitor screen.

Flow:

  1. A bill is modified (e.g., created, updated, printed).
  2. An event is broadcasted using MediatR.
  3. The SSE service listens and publishes the event to connected frontend clients.
  4. The UI updates in real-time without polling.

Events are queued internally to ensure delivery even during high load.


🧾 Financial Account Creation

When a user, customer, or delivery driver is created in the system:

  • A financial account is automatically created via the AccountsService.
  • This ensures that every actor is financially linked in the journal system.

Account types include:

EntityAccount Use
UserCash transaction recording
CustomerTrack sales & debts
DeliveryDriverTrack safari bill assignments

💸 Bill Financial Processing (Project Legolas Integration)

Component: BillFinanceProcessor

Trigger:

  • Listens to bill completion events (e.g., OrderFinished, SafariOrderFinished)

Flow:

  1. Deserializes the event to BillResponse.

  2. Determines the correct account:

    • For Safari → Delivery Driver
    • Otherwise → Customer
  3. Begins a DB transaction.

  4. Creates a SaleTransactionRequest:

    • Includes Revenue, Discounts, and Paid amounts
  5. Converts request → SaleTransaction and appends it to journal in Project Legolas

  6. Commits the transaction.

  7. Associates the transaction to the bill.

Transactions are handled safely and ensure data consistency with rollback support.


⚙️ Tech Stack and Libraries

FeatureLibrary/Tool
API RoutingFastEndpoints
Event MediationMediatR
Real-Time CommunicationServer-Sent Events (SSE)
Database ORMEF Core
Financial LedgerProject Legolas
External Print ServiceProject Jupiter
Pdf document generatorQuestPDF

🧮 Constants and Settings

  • Printer Name is configured via AppSettings.InvoiceSettings.PrinterName
  • Logo Image for receipts is loaded from uploaded files based on settings
  • Business ID and chart of accounts are managed via Consts.BusinessId

📌 Summary

Project Sardine is a service-oriented backend system that handles:

  • Checkout and billing logic
  • Delegates printing to a dedicated external print microservice
  • Broadcasts events using MediatR and SSE
  • Ensures that each user or customer has a tied financial account
  • Processes journal transactions using Project Legolas

This architecture makes the system modular, real-time, and financially accountable, supporting extensibility and scalability in a production-grade environment.